<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>材料替换</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link href="../../css/app.css" />
		<style>
			.mui-bar {
				background-color: #0088BB;
			}
			
			.mui-title {
				color: #FFFFFF
			}
			
			a {
				color: #FFFFFF
			}
		</style>
	</head>

	<body>

		<div id="welding">
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
				<h1 class="mui-title">设备：{{EqpId}}</h1><br>
			</header>

			<div class="mui-content">
				<div v-html="progressbar"> </div>
				<div class="mui-input-row" v-show="Type != 'Capillary'">
					<!--
                    	作者：offline
                    	时间：2018-01-31
                    	描述：
                    	<input type="text" placeholder="扫码或或输入" class="mui-input-clear"  v-model="meteriseStr" value="" />
                    -->
					<input ref="input" id="inputId" type="text" @keyup="keyup" class="mui-input-clear" placeholder="请扫描需要更换的物料条码">
				</div>
				<ul id="list" class="mui-table-view mui-table-view-chevron">
					<template v-if="Type == 'Wire' ">
						<li class="mui-table-view-divider">铜线更换</li>
						<li class="mui-table-view-cell">
							<label>批次:</label>{{MesMaterial.SeqNo}}
						</li>
						<li class="mui-table-view-cell">
							<label>编号:</label> {{MesMaterial.MaterialPartNo}}
						</li>
						<li class="mui-table-view-cell">
							<label>直径:</label>{{MesMaterial.Size}}
						</li>
						<li class="mui-table-view-cell">
							<label>生产日期:</label>{{MesMaterial.RemainTime}}
						</li>
					</template>
					<template v-else-if="Type == 'Capillary'">
						<!--<template></template>-->
						<li class="mui-table-view-divider">劈刀更换</li>
						<!--<li class="mui-table-view-cell">-->
						<!--<label>批次:</label>{{MesMaterial.SeqNo}}-->
						<div class="mui-input-row">
							<label>料号</label>
							<input type="text" placeholder="请扫描长条码" class="mui-input-clear" id='CapillarySeqNo' />
						</div>

						<!--</li>-->
						<!--<li class="mui-table-view-cell">-->
						<!--<label>编号:</label>{{MesMaterial.MaterialPartNo}}-->
						<div class="mui-input-row">
							<label>序列号</label>
							<input type="text" placeholder="请扫描短条码" class="mui-input-clear" id='CapillaryMaterialPartNo'>
						</div>

						<!--</li>-->
					</template>
					<template v-else-if="Type== 'Wafer'">
						<li class="mui-table-view-divider">
							晶圆更换
						</li>
						<li class="mui-table-view-cell">
							Device:<span>{{MesMaterial.Device}}</span>
						</li>
						<li class="mui-table-view-cell">
							WaferSource:<span>{{MesMaterial.WaferSource}}</span>
						</li>
						<li class="mui-table-view-cell">
							焊接图:<span>{{MesMaterial.Diagram}}</span>
						</li>
						<li class="mui-table-view-cell">
							批次号:<span>{{MesMaterial.MaterialPartNo}}</span>
						</li>
					</template>
					<template v-else-if="Type == 'Expoxy'">
						<li class="mui-table-view-divider">
							银浆更换
						</li>
						<li class="mui-table-view-cell">
							物料编码:<span>{{MesMaterial.MaterialPartNo}}</span>
						</li>
						<li class="mui-table-view-cell">
							解冻完成:<span>{{MesMaterial.ThawEndTime}}</span>
						</li>
					</template>

					<template v-else-if="Type== 'HubBlade'">
						<li class="mui-table-view-divider">
							晶圆刀片更换
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==false">
							型号:<span>{{MesMaterial.MaterialPartNo}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==true">
							型号:<span>{{MesMaterial.MATERIALPARTNO}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==false">
							刀刃长度:<span>{{MesMaterial.SawLength}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==true">
							刀刃长度:<span>{{MesMaterial.SAWLENGTH}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==false">
							刀刃厚度:<span>{{MesMaterial.SawThickness}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==true">
							刀刃厚度:<span>{{MesMaterial.SAWTHICKNESS}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==false">
							刀批次号:<span>{{MesMaterial.SeqNo}}</span>
						</li>
						<li class="mui-table-view-cell" v-if="isWaferSaw==true">
							刀批次号:<span>{{MesMaterial.SEQNO}}</span>
						</li>
					</template>
					<template v-else-if="Type == 'HublessBlade' ">
						<li class="mui-table-view-divider">
							芯片刀片更换
						</li>
						<li class="mui-table-view-cell">
							批次号:<span>{{MesMaterial.SeqNo}}</span>
						</li>
						<li class="mui-table-view-cell">
							外径:<span>{{MesMaterial.ExternalDiameter}}</span>
						</li>
						<li class="mui-table-view-cell">
							内径:<span>{{MesMaterial.InternalDiameter}}</span>
						</li>
						<li class="mui-table-view-cell">
							厚度:<span>{{MesMaterial.SawThickness}}</span>
						</li>
						<li class="mui-table-view-cell">
							型号:<span>{{MesMaterial.ID}}</span>
						</li>
					</template>
				</ul>
			</div>
			<div class="mui-row">&nbsp;</div>
			<div class="mui-row">&nbsp;</div>
			<button type="button" v-on:click="sbCommit" class="mui-btn mui-btn-primary mui-btn-block">确 定</button>
		</div>
	</body>

</html>

<script type="text/javascript" src="../../base.js"></script>
<script src="../../js/mui.min.js"></script>
<script src="../../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	mui.init({});
	/**自动聚焦start**/
	var nativeWebview, imm, InputMethodManager;
	var initNativeObjects = function() {
		if(mui.os.android) {
			var main = plus.android.runtimeMainActivity();
			var Context = plus.android.importClass("android.content.Context");
			InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
			imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
		} else {
			nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
		}
	};
	var showSoftInput = function() {
		var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
		if(mui.os.android) {
			//强制当前webview获得焦点
			plus.android.importClass(nativeWebview);
			nativeWebview.requestFocus();
			imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
		} else {
			nativeWebview.plusCallMethod({
				"setKeyboardDisplayRequiresUserAction": false
			});
		}
		setTimeout(function() {
			//此处可写具体逻辑设置获取焦点的input
			var inputElem = document.querySelector('input');
			inputElem.focus();
		}, 1);
	};

	mui.plusReady(function() {
		initNativeObjects();
		showSoftInput();
	});

	/**自动聚焦end**/
	function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for(var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if(pair[0] == variable) {
				return pair[1];
			}
		}
		return "";
	};

	function backF(id) {
		document.getElementById(id).click()
	}

	var vm = new Vue({
		el: '#welding',
		data: {
			EqpId: "",
			OPID: localStorage.user,
			Type: "",
			Materials: {
				MesMaterial: {}
			},
			meteriseStr: "",
			MesMaterial: [],
			progressbar: "",
			request: false, //校验是否通过
			WaferSawSeqNo: '',
			isWaferSaw: false //是否原厂物料

		},
		mounted: function() {
			var _this = this;
			_this.Type = getQueryVariable("Type");
			console.log(_this.Type)
			_this.EqpId = getQueryVariable("EqpId");
		},
		methods: {

			spStr: function(str, Type, partten) {
				var _this = this
				var strArray = str.split(partten);
				var map = {}
				try {
					switch(Type) {
						case "Wire":

							if(strArray.length < 4) {
								_this.request = false
							} else {
								map.Size = (strArray[0].split(" "))[0]
								map.MaterialPartNo = strArray[1]
								map.SeqNo = strArray[2]
								map.RemainTime = strArray[3]
								map.Type = Type
								map.Device = ""
								map.WaferSource = ""
								map.Diagram = ""
								map.ThawEndTime = ""
								map.SawLength = ""
								map.SawThickness = ""
								map.ExternalDiameter = ""
								map.InternalDiameter = ""
								_this.request = true
							}
							break;
						case "Capillary":
							_this.request = true
							//							if(strArray.length > 2) {
							//								_this.request = false
							//							} else {
							//								map.MaterialPartNo = strArray[0]
							//								map.SeqNo = strArray[1]
							//								map.Type = Type
							//								map.Size = ""
							//								map.RemainTime = ""
							//								map.Device = ""
							//								map.WaferSource = ""
							//								map.Diagram = ""
							//								map.ThawEndTime = ""
							//								map.SawLength = ""
							//								map.SawThickness = ""
							//								map.ExternalDiameter = ""
							//								map.InternalDiameter = ""
							//								//								_this.request = true
							//							}
							break;
						case "HublessBlade":

							if(strArray.length < 5) {
								_this.request = false
							} else {
								map.SeqNo = strArray[0]
								map.ExternalDiameter = strArray[1]
								map.InternalDiameter = strArray[2]
								map.SawThickness = strArray[3]
								map.MaterialPartNo = strArray[3]
								map.Size = ""
								map.RemainTime = ""
								map.Device = ""
								map.WaferSource = ""
								map.Diagram = ""
								map.ThawEndTime = ""
								map.SawLength = ""
								map.SawThickness = ""
								map.ExternalDiameter = ""
								map.InternalDiameter = ""
								map.Type = Type
								_this.request = true
							}
							break;
						case "Wafer":

							if(strArray.length < 4) {
								_this.request = false
							} else {
								map.Device = strArray[0]
								map.WaferSource = strArray[1]
								map.Diagram = strArray[2]
								map.MaterialPartNo = strArray[3]
								map.Size = ""
								map.RemainTime = ""
								map.Device = ""
								map.WaferSource = ""
								map.Diagram = ""
								map.ThawEndTime = ""
								map.SawLength = ""
								map.SawThickness = ""
								map.ExternalDiameter = ""
								map.InternalDiameter = ""
								map.Type = Type
								_this.request = true
							}
							break;
						case "Expoxy":

							if(strArray.length < 5) {
								_this.sbCommit = false
							} else {
								map.MaterialPartNo = strArray[0]
								//								map.WaferSource = strArray[1]
								map.ThawEndTime = strArray[2]
								//								map.MaterialPartNo = strArray[3]
								map.Size = ""
								map.RemainTime = ""
								map.Device = ""
								map.WaferSource = ""
								map.Diagram = ""
								map.ThawEndTime = ""
								map.SawLength = ""
								map.SawThickness = ""
								map.ExternalDiameter = ""
								map.InternalDiameter = ""
								map.Type = Type
								_this.request = true
							}
							break;
						case "HubBlade":

							if(strArray.length == 4) {

								map.MaterialPartNo = strArray[0]
								map.SawLength = strArray[1]
								map.SawThickness = strArray[2]
								map.SeqNo = strArray[3]
								map.Size = ""
								map.RemainTime = ""
								map.Device = ""
								map.WaferSource = ""
								map.Diagram = ""
								map.ThawEndTime = ""

								map.ExternalDiameter = ""
								map.InternalDiameter = ""
								map.Type = Type
								_this.request = true
							} else if(strArray.length == 1) {

								if(str.length  >  15) {             
									if(str.substr(str.length  -  14,  1)  ==  "H") {                    
										str  =  str.substr(str.length  -  14,  12);             
									} 
									else  {                    
										if (str.substr(str.length  -  15,  1)  ==  "H") {                           
											str  =  str.substr(0,  str.length  -  1);                           
											str  =  str.substr(str.length  -  14,  12);                    
										}             
									}      
								}

								_this.WaferSawSeqNo = str
								_this.getWaferSaw()
								_this.isWaferSaw = true

							} else {
								_this.request = false
							}
							break;
						default:
							break;
					}
				} catch(e) {
					map.Size = ""
					map.MaterialPartNo = ""
					map.ID = ""
					map.RemainTime = ""
					map.Type = ""
				}
				return map
			},

			sbCommit: function() {
				var _this = this;
				console.log(_this.request)
				_this.progressbar = "<p class='mui-progressbar mui-progressbar-infinite'></p>";
				//			var spStr = _this.spStr("0.8 mil;220028;CL77122C-0411;2017/07/05", _this.Type, ";");
				//					var spStr = _this.spStr(e.target.value, _this.Type, /[;^]/);
				// ^是wafer的判断规则 wafer不属于物料 所以去掉 ；是刀片的判断规则
				var SeqNo = ''
				var MaterialPartNo = ''
				var SawThickness = ''
				var SawLength = ''
				//				var spStr = _this.spStr(_this.meteriseStr, _this.Type, /[;^]/);

				if(_this.Type == 'Capillary') {
					SeqNo = document.getElementById("CapillarySeqNo").value.trim();
					console.log(SeqNo)
					MaterialPartNo = document.getElementById("CapillaryMaterialPartNo").value.trim();
					_this.request = true
				} else {
					console.log(_this.isWaferSaw)
					if(_this.isWaferSaw == true) {
						console.log(_this.request)
						SeqNo = _this.MesMaterial.SEQNO
						MaterialPartNo = _this.MesMaterial.MATERIALPARTNO
						SawThickness = _this.MesMaterial.SAWTHICKNESS
						SawLength = _this.MesMaterial.SAWLENGTH

					} else {
						SeqNo = _this.MesMaterial.SeqNo
						MaterialPartNo = _this.MesMaterial.MaterialPartNo
						SawThickness = _this.MesMaterial.SawThickness
						SawLength = _this.MesMaterial.SawLength
					}

				}
				if(_this.request == false) {
					mui.alert("请检查扫描的物料条码是否正确")
				} else {

					//					console.log(SeqNo)
					mui.ajax(base + '/ChangeMeterial.json', {
						data: {
							EqpId: _this.EqpId,
							OPID: _this.OPID,
							Name: _this.OPID,
							Type: _this.Type,
							Size: _this.MesMaterial.Size,
							RemainTime: _this.MesMaterial.RemainTime,
							SeqNo: SeqNo,
							MaterialPartNo: MaterialPartNo,

							Device: _this.MesMaterial.Device,
							WaferSource: _this.MesMaterial.WaferSource,
							Diagram: _this.MesMaterial.Diagram,
							ThawEndTime: _this.MesMaterial.ThawEndTime,
							SawLength: SawLength,
							SawThickness: SawThickness,
							ExternalDiameter: _this.MesMaterial.ExternalDiameter,
							InternalDiameter: _this.MesMaterial.InternalDiameter
						},
						dataType: 'json',
						type: 'post',
						//				timeout:10000, 
						success: function(data) {
							_this.progressbar = ""
							navigator.vibrate = navigator.vibrate ||
								navigator.webkitVibrate ||
								navigator.mozVibrate ||
								navigator.msVibrate;
							if(data != null && data.ISSHOW) {
								navigator.vibrate([400, 300, 200, 100]);
								alert(data.MESSAGE);
								localStorage.eqpId = _this.EqpId
								//								window.history.go(-1);
								window.history.back()
								//								location.reload();
								//							mui.back();
								//							var list = plus.webview.currentWebview().opener();
								//							//触发父页面的自定义事件(refresh),从而进行刷新
								//							mui.fire(list, 'refresh');
								//							//返回true,继续页面关闭逻辑
								//							return true;
								//							window.open('matReplace.html');
							} else {
								alert("更新失败!")
							}
						},
						error: function(xhr, type, errorThrown) {
							alert("通信错误!")
							_this.progressbar = ""
						}
					});
				}

			},
			keyup(e) {
				if(e === null || e.keyCode === 13 || e.keyCode == 66) {
					var _this = this;
					//					var spStr = _this.spStr(e.target.value, _this.Type, /[;^]/);
					// ^是wafer的判断规则 wafer不属于物料 所以去掉 ；是刀片的判断规则  DB的时候是物料
					var spStr = _this.spStr(e.target.value, _this.Type, /[;^]/);

					//判断扫描到的物料规则
					if(e.target.value != null && _this.request == true) {
						_this.meteriseStr = e.target.value
						_this.MesMaterial = _this.spStr(e.target.value, _this.Type, /[;^]/)
						//						this.sbCommit()
						//清空文本
						e.target.value = '';
					} else {
						//不正确清空显示栏
						_this.MesMaterial = [];
					}
					//关闭软键盘
					document.activeElement.blur();
				}
			},
			getWaferSaw: function() {

				var _this = this;
				var WaferSawSeqNo = _this.WaferSawSeqNo

				mui.ajax(base + '/WaferSaw/index.json', {
					data: {
						SeqNo: WaferSawSeqNo
					},
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 30000, //超时时间设置为10秒；
					success: function(data) {

						if(data == 0) {
							mui.alert('数据库无此物料，请咨询EAP')
							_this.request = false
						} else {
							_this.MesMaterial = data
							_this.request = true
							console.log(data.MATERIALPARTNO)
							console.log(_this.isWaferSaw)
						}

					},
					error: function(xhr, type, errorThrown) {
						console.log(errorThrown + "type" + type)
					}
				});
			}
		}
	})

	document.onkeydown = function(e) { //对整个页面文档监听
		var keyNum = window.event ? e.keyCode : e.which; //获取被按下的键值
		//判断如果用户按下了回车键（keycody=13）
		//console.log("keyNum:"+keyNum);
		if(keyNum == 119) {
			document.getElementById("inputId").focus();
		}
	}
</script>